#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "ElaWidget.h"
#include "ElaContentDialog.h"
#include "ElaPushButton.h"
#include "ElaTheme.h"
#include <QVBoxLayout>
#include <QPushButton>

#include "ConfirmDialog.h"
#include "SettingsDialog.h"
#include "UserInfoDialog.h"

class MainWindow : public ElaWidget
{
    Q_OBJECT
  public:
    MainWindow(QWidget* parent = nullptr) : ElaWidget(parent)
    {
        setWindowTitle("ElaContentDialog 示例");
        resize(600, 400);
        setWindowButtonFlags(ElaAppBarType::StayTopButtonHint | ElaAppBarType::MinimizeButtonHint | ElaAppBarType::MaximizeButtonHint | ElaAppBarType::CloseButtonHint | ElaAppBarType::ThemeChangeButtonHint | ElaAppBarType::NavigationButtonHint);

        auto* layout = new QVBoxLayout(this);

        auto* confirmBtn = new ElaPushButton("显示确认对话框", this);
        auto* settingsBtn = new ElaPushButton("显示设置对话框", this);
        auto* userInfoBtn = new ElaPushButton("显示用户信息对话框", this);

        layout->addWidget(confirmBtn);
        layout->addWidget(settingsBtn);
        layout->addWidget(userInfoBtn);
        layout->addStretch();

        connect(confirmBtn, &ElaPushButton::clicked, this, &MainWindow::showConfirmDialog);
        connect(settingsBtn, &ElaPushButton::clicked, this, &MainWindow::showSettingsDialog);
        connect(userInfoBtn, &ElaPushButton::clicked, this, &MainWindow::showUserInfoDialog);
    }

  private Q_SLOTS:
    void showConfirmDialog()
    {
        auto* dialog = new ConfirmDialog(this);
        connect(dialog, &ElaContentDialog::rightButtonClicked, this, [=]() { qDebug() << "在主窗口中处理删除逻辑"; });
        dialog->show();
    }

    void showSettingsDialog()
    {
        auto* dialog = new SettingsDialog(this);
        dialog->show();
    }

    void showUserInfoDialog()
    {
        auto* dialog = new UserInfoDialog(this);
        connect(dialog, &ElaContentDialog::rightButtonClicked, this, [=]() {
            // 可以在这里获取对话框数据
            auto* userDialog = qobject_cast<UserInfoDialog*>(dialog);
            if (userDialog)
            {
                qDebug() << "获取到用户信息:" << userDialog->getName();
            }
        });
        dialog->show();
    }
};

#endif  // MAINWINDOW_H